package com.example.recyclerviewtest;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;


public class TitleLayout extends LinearLayout {
    public TitleLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        //加载布局
        LayoutInflater.from(context).inflate(R.layout.title, this);

        Button titleBack = findViewById(R.id.title_back);
        Button titleMenu = findViewById(R.id.title_menu);

        //设置返回按钮的点击事件
        titleBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity) getContext()).finish();
            }
        });

        //设置菜单按钮的点击事件
        titleMenu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 设置功能菜单
                Toast.makeText(getContext(), "menu", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
